#include "stdafx.h"
#include "MapTileRender.h"
#include "texture.h"

CMapTileRender::CMapTileRender()
{

}

CMapTileRender::~CMapTileRender()
{

}

void CMapTileRender::Render()
{
    TextureInfo *texinfo = CD3DManager::Instance().GetTextureInfo( m_textureid );
    CHECK_PTR_VOID( texinfo );
    IDirect3DDevice9 *pDevice = CD3DManager::Instance().GetDevice();
    float minx = (float)m_x;
    float miny = (float)m_y;
    float maxx = (float)(m_x+m_sizex-1);
    float maxy = (float)(m_y+m_sizey-1);
    Vertex_RHW_CLR_TEX ver[]=
    {
        {minx,miny,0.0f,1.0f,m_color,m_u1,m_v1},
        {maxx,miny,0.0f,1.0f,m_color,m_u2,m_v1},
        {maxx,maxy,0.0f,1.0f,m_color,m_u2,m_v2},

        {minx,miny,0.0f,1.0f,m_color,m_u1,m_v1},
        {maxx,maxy,0.0f,1.0f,m_color,m_u2,m_v2},
        {minx,maxy,0.0f,1.0f,m_color,m_u1,m_v2},
    };
    pDevice->SetTexture( 0, texinfo->texture );
    pDevice->SetFVF(Vertex_RHW_CLR_TEX::FVF);
    pDevice->DrawPrimitiveUP( D3DPT_TRIANGLELIST, 2, ver, sizeof(Vertex_RHW_CLR_TEX) );
}

void CMapTileRender::SetColor( int color )
{
    m_color = color;
}

